<?php
/**
 * Joomla! 1.5 component JoomGPSTracks
 *
 * @version $Id: cats.php 2009-06-24 15:40:19 svn $
 * @author Michael Pfister
 * @package joomGPStracks
 * @subpackage frontend
 * @license GNU/GPL
 * @filesource
 *
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.model');

class JoomgpstracksModelCats extends JModel  {

    function getCats()  {
        global $mainframe;

        $db = JFactory::getDBO();

        $query = "SELECT * FROM #__gps_cats"
                . "\n WHERE published=1"
                . "\n ORDER BY ordering";

        $db->setQuery($query);
        $rows = $db->loadObjectList();
        $limit = count($rows);
        $children = array();
	foreach ($rows as $v ) {
		$pt 	= $v->parent;
		$list 	= @$children[$pt] ? $children[$pt] : array();
		array_push( $list, $v );
		$children[$pt] = $list;
	}
        $list = JHTML::_('menu.treerecurse', 0, '', array(), $children );
        $list = array_slice($list,0,$limit);

        return $list;
    }
}
?>
